﻿using Abp.Dependency;
using Mt.Site.Application.FileFinder;
using Mt.Site.Core.Base.Utils.FileIO.Upload;
using Mt.Site.Core.Storage;
using Mt.Site.Core.Storage.File_;
using System.Threading.Tasks;

namespace Mt.Site.Application.FileUpload.Impl
{
    public class UploadStrategy : IUploadStrategy, ITransientDependency
    {
        private readonly IFileLibraryManager _fileLibraryManager;
        private readonly IFileObjectManager _fileObjectManager;

        private readonly FileLibraryUploadHelper _fileLibraryUploadHelper;

        public UploadStrategy(
            IFileLibraryManager fileLibraryManager,
            IFileObjectManager fileObjectManager,
            FileLibraryUploadHelper fileLibraryUploadHelper)
        {
            _fileLibraryManager = fileLibraryManager;
            _fileObjectManager = fileObjectManager;
            _fileLibraryUploadHelper = fileLibraryUploadHelper;
        }

        public bool NeedSha1 => true;

        public async Task<CheckFileIsExistResult> CheckFileIsExist(string sha1)
        {
            return await _fileLibraryUploadHelper.CheckFileIsExist(_fileLibraryManager, sha1);
        }

        public async Task AfterProcessPic(UpfileResult result)
        {
            await _fileObjectManager.AddfileObjectEx(result.UploadFileInfos, result.UploadFileInfo.FileUrl, result.ExName);
        }
    }
}
